#ifndef __SOCK_H__
#define __SOCK_H__

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <fcntl.h>

typedef void (*pprocess)(void *);
     
typedef struct sockparams
{
  int sock;
  int sockin;
  struct sockaddr_in servername;
  unsigned int port;
  fd_set active_fd_set, read_fd_set;
  struct timeval wait;
  pprocess callback;
  void * apppar;
} sockparams;

typedef struct sockbuf
{
  void * apppar;
  unsigned int size;
  char * buf;
} sockbuf;
     
void bk_writetoserver (int filedes, char * message, unsigned int length);
struct sockparams * bk_clientinit(unsigned int m_port, char * m_serverhost);
void bk_clientfinalize(struct sockparams * m_params);     
int bk_clientconnect(struct sockparams * m_params);     
struct sockbuf * bk_readfromclient (int filedes, int sz);
sockparams * bk_serverinit(unsigned int m_port, int m_sec, int m_usec);
void bk_serverfinalize(struct sockparams * m_serv);
int bk_serverstep (struct sockparams * m_serv, int m_stepsz);
int bk_makesocket (uint16_t port);
void bk_initsockaddr (struct sockaddr_in *name, const char *hostname, uint16_t port);

#endif
